import React, { useState, useEffect } from 'react';

import {
    NavBar,
    Icon,
    List,
    Button,
    Toast,
    WhiteSpace,
    Accordion,
    Modal, TextareaItem
} from 'antd-mobile';

import { R, VOID, RESUME_STATUSES } from '@/assets/js/dict.js'

import { GetDetailsResume, postDeleteResume, PostCommitResume } from '@/api/tutor/biographicalNotes.js'


import './biographicalNotesDetails.scss';

const alert = Modal.alert;

/**
 * 简历详情页
 * @param props
 * @returns {*}
 * @constructor
 */
function BiographicalNotesDetails (props) {

    const [biographicalNotesDetailsObject, setBbiographicalNotesDetailsObject] = useState({})
    let [flush, setFlush] = useState("");

    function doFlush(){
        setFlush(new Date().getTime());
    }


    // 去修改
    let handleToUpDate = () => {

        //进入编辑页，将id放入缓存
        sessionStorage.setItem("resume_id", biographicalNotesDetailsObject.id);
        props.history.push({
            pathname: 'biographicalNotes',
            params: {
                'type': 'update',
                'id': biographicalNotesDetailsObject.id
            }
        })
    };

    // 删除简历
    let handleDel = () => {
        alert('删除', '您确定要删除此简历吗???', [
            { text: '取消' },
            {
                text: '确定', onPress: () => {
                    let postData = {
                        'id': sessionStorage.getItem("resume_id")
                    };
                    postDeleteResume(postData).then(res => {
                        if (res.code === '000000') {
                            console.log('res -------->>>', res);
                            alert('提示', '删除成功', [
                                {
                                    text: '知道了', onPress: () => {
                                        sessionStorage.removeItem("resume_id");
                                        props.history.push({
                                            pathname: '/resumeList'
                                        });
                                    }
                                },
                            ])
                        }
                    }).catch(err => {

                    })
                }
            },
        ]);
    }


    let handleCommit = () => {
        alert('提交审核', '您确定要提交此简历吗???', [
            { text: '取消' },
            {
                text: '确定', onPress: () => {
                    let id = sessionStorage.getItem("resume_id");
                    PostCommitResume({ id: id }).then(res => {
                        if (res.code == '000000') {
                            console.log('res -------->>>', res);
                            alert('提示', '提交成功', [
                                {
                                    text: '知道了', onPress: () => {
                                        doFlush();
                                        // props.history.push({
                                        //     pathname: '/main',
                                        //     query: { selectedTab: "my" },
                                        // })
                                    }
                                },
                            ])
                        }
                    }).catch(err => {

                    })
                }
            },
        ]);
    }

    // 选择课程类型  文 / 理
    let handleCourseType = () => {
        console.log('Resume.class_type  ---------->>>>', props.biographicalNotesDetailsObject)
        if (biographicalNotesDetailsObject.class_type == '文科') {
            return (
                <div>
                    <List.Item
                        extra={biographicalNotesDetailsObject.college_politics}
                    >高考-政治</List.Item>
                    <List.Item
                        extra={biographicalNotesDetailsObject.college_history}
                    >高考-历史</List.Item>
                    <List.Item
                        extra={biographicalNotesDetailsObject.college_geography}
                    >高考-地理</List.Item>
                </div>
            )
        } else if (biographicalNotesDetailsObject.class_type == '理科') {
            return (
                <div>
                    <List.Item
                        extra={biographicalNotesDetailsObject.college_physics}
                    >高考-物理</List.Item>
                    <List.Item
                        extra={biographicalNotesDetailsObject.college_chemie}
                    >高考-化学</List.Item>
                    <List.Item
                        extra={biographicalNotesDetailsObject.college_biology}
                    >中考-生物</List.Item>
                </div>
            )
        }
    }

    useEffect(() => {
        // 查看孩子详细信息 GET
        console.log('props -------->>>', props);
        let postData = {};
        if (props.location.params) {
            postData.id = props.location.params.id;
            sessionStorage.setItem("resume_id", postData.id);
        } else {
            let id = sessionStorage.getItem("resume_id");
            postData.id = id;
        }
        GetDetailsResume(postData).then(res => {
            if (res.code == '000000') {
                console.log('res -------->>>', res);
                setBbiographicalNotesDetailsObject(res.responseData)
            }
        }).catch(err => {
            console.error(err);
        })
    }, [flush]);

    function back() {
        //消除缓存
        sessionStorage.removeItem("resume_id");
        props.history.push({
            pathname: '/resumeList'
        });
    }


    function edit() {
        if(biographicalNotesDetailsObject.status === RESUME_STATUSES.NORMAL){
            alert('提示', '该简历已经通过审核，若修改需再次提交审核，您确定要修改吗？', [
                {text: '取消', onPress: () => console.log('cancel')},
                {
                    text: '确定', onPress: () => {
                        handleToUpDate();
                    }
                },
            ]);
        }else {
            handleToUpDate();
        }
    }

    return (
        <div className="student-details">
            <div className="page-title  student-tit">
                <NavBar
                    mode="light"
                    icon={<Icon type="left" />}
                    onLeftClick={back}
                    rightContent={[
                        <span key={"edit"} style={{display: biographicalNotesDetailsObject.status === RESUME_STATUSES.AUDITING? 'none': 'block'}} onClick={edit}>编辑</span>,
                    ]}
                >
                    我的简历
                </NavBar>

            </div>
            <div className="page-content student-content">
                <div className="student-content-piece">
                    <div className="form-box">
                        <div className="form-tit">
                            <i className="mini-block"></i>
                            <strong>基本信息</strong>
                        </div>
                        <div className="form-con">
                            <List>
                                <List.Item extra={biographicalNotesDetailsObject.display}
                                >标题</List.Item>
                                <List.Item extra={biographicalNotesDetailsObject.status}
                                >状态</List.Item>
                                <List.Item extra={biographicalNotesDetailsObject.school}
                                >学校（全称）</List.Item>
                                <List.Item extra={biographicalNotesDetailsObject.college}
                                >学院（全称）</List.Item>
                                <List.Item extra={biographicalNotesDetailsObject.profession}
                                >专业</List.Item>
                            </List>
                        </div>

                        <div className="form-tit">
                            <i className="mini-block"></i>
                            <strong>教育信息</strong>
                        </div>
                        <div className="form-con">
                            <List>
                                <List.Item
                                    extra={biographicalNotesDetailsObject.grade}
                                >年级</List.Item>
                                <List.Item
                                    extra={biographicalNotesDetailsObject.zkzf}
                                >中考总分</List.Item>
                                <List.Item
                                    extra={biographicalNotesDetailsObject.high_school_province}
                                >中考省份</List.Item>
                                <Accordion accordion className="subject-list">
                                    <Accordion.Panel header="中考单科成绩" key="1">
                                        <List>
                                            <List.Item
                                                extra={biographicalNotesDetailsObject.high_language}
                                            >中考-语文</List.Item>
                                            <List.Item
                                                extra={biographicalNotesDetailsObject.high_math}
                                            >中考-数学</List.Item>
                                            <List.Item
                                                extra={biographicalNotesDetailsObject.high_english}
                                            >中考-英语</List.Item>
                                            <List.Item
                                                extra={biographicalNotesDetailsObject.high_physics}
                                            >中考-物理</List.Item>
                                            <List.Item
                                                extra={biographicalNotesDetailsObject.high_chemie}
                                            >中考-化学</List.Item>
                                            <List.Item
                                                extra={biographicalNotesDetailsObject.high_politics}
                                            >中考-政治</List.Item>
                                            <List.Item
                                                extra={biographicalNotesDetailsObject.high_history}
                                            >中考-历史</List.Item>
                                            <List.Item
                                                extra={biographicalNotesDetailsObject.high_geography}
                                            >中考-地理</List.Item>
                                            <List.Item
                                                extra={biographicalNotesDetailsObject.high_biology}
                                            >中考-生物</List.Item>
                                        </List>
                                    </Accordion.Panel>
                                </Accordion>
                                <List.Item
                                    extra={biographicalNotesDetailsObject.college_school_province}
                                >高考省份</List.Item>
                                <List.Item
                                    extra={biographicalNotesDetailsObject.class_type}
                                > 课程类型
                                </List.Item>
                                <List.Item
                                    extra={biographicalNotesDetailsObject.gkzf}
                                >高考总分</List.Item>
                                <List.Item
                                    extra={biographicalNotesDetailsObject.college_score_ranking}
                                >高考成绩排名</List.Item>
                                <Accordion accordion className="subject-list">
                                    <Accordion.Panel header="高考单科成绩" key="2">
                                        <List>
                                            <List.Item
                                                extra={biographicalNotesDetailsObject.college_language}
                                            >高考-语文</List.Item>
                                            <List.Item
                                                extra={biographicalNotesDetailsObject.college_math}
                                            >高考-数学</List.Item>
                                            <List.Item
                                                extra={biographicalNotesDetailsObject.college_english}
                                            >高考-英语</List.Item>

                                            {handleCourseType()}


                                        </List>
                                    </Accordion.Panel>
                                </Accordion>
                            </List>
                            <Accordion accordion className="my-accordion">
                                <Accordion.Panel header="擅长的辅导内容" key="1">
                                    <div className="textarea-box">
                                        <List.Item
                                            wrap
                                            extra={biographicalNotesDetailsObject.skilled}
                                            multipleLine
                                        ></List.Item>
                                    </div>
                                </Accordion.Panel>
                                <Accordion.Panel header="家教经验" key="2">

                                    <div className="textarea-box">
                                        <TextareaItem
                                            title={'家教经验一'}
                                            placeholder="无"
                                            rows="6"
                                            autoHeight
                                            editable={false}
                                            value={biographicalNotesDetailsObject.experience_one}
                                        />
                                    </div>

                                    <div className="textarea-box">
                                        <TextareaItem
                                            title={'家教经验二'}
                                            placeholder="无"
                                            rows="6"
                                            autoHeight
                                            editable={false}
                                            value={biographicalNotesDetailsObject.experience_tow}
                                        />
                                    </div>

                                    <div className="textarea-box">
                                        <TextareaItem
                                            title={'家教经验三'}
                                            placeholder="无"
                                            rows="6"
                                            autoHeight
                                            editable={false}
                                            value={biographicalNotesDetailsObject.experience_three}
                                        />
                                    </div>
                                </Accordion.Panel>
                                <Accordion.Panel header="获奖情况" key="3">
                                    <div className="textarea-box">
                                        <List.Item
                                            extra={biographicalNotesDetailsObject.prize}
                                            wrap
                                        ></List.Item>
                                    </div>
                                </Accordion.Panel>
                                <Accordion.Panel header="其他特长" key="4">
                                    <div className="textarea-box">
                                        <List.Item
                                            extra={biographicalNotesDetailsObject.qttc}
                                            wrap
                                        ></List.Item>
                                    </div>
                                </Accordion.Panel>
                            </Accordion>
                        </div>
                        <div className="form-tit">
                            <i className="mini-block"></i>
                            <strong>其他信息</strong>
                        </div>
                        <div className="form-con">
                            <Accordion accordion className="my-accordion">
                                <Accordion.Panel header="自我评价" key="1">
                                    <div className="textarea-box">
                                        <TextareaItem
                                            placeholder="无"
                                            rows="6"
                                            autoHeight
                                            editable={false}
                                            value={biographicalNotesDetailsObject.self_evaluation}
                                        />
                                    </div>
                                </Accordion.Panel>
                                <Accordion.Panel header="教学理念" key="2">
                                    <div className="textarea-box">
                                        <TextareaItem
                                            placeholder="无"
                                            rows="6"
                                            autoHeight
                                            editable={false}
                                            value={biographicalNotesDetailsObject.teaching_idea}
                                        />
                                    </div>
                                </Accordion.Panel>
                                <Accordion.Panel header="备注说明" key="3">
                                    <div className="textarea-box">
                                        <TextareaItem
                                            placeholder="无"
                                            rows="6"
                                            autoHeight
                                            editable={false}
                                            value={biographicalNotesDetailsObject.note}
                                        />
                                    </div>
                                </Accordion.Panel>
                            </Accordion>
                        </div>
                        <div className="form-footer">
                            <Button type="primary" onClick={handleDel} style={{backgroundColor:'#E94F4F',
                                display: (biographicalNotesDetailsObject.status === RESUME_STATUSES.AUDITING || biographicalNotesDetailsObject.status===RESUME_STATUSES.NORMAL) ? 'none': 'block' }}>删除简历</Button>
                            <Button type="primary"
                                style={{ display: biographicalNotesDetailsObject.status === RESUME_STATUSES.EDITING ? 'block' : 'none' }}
                                onClick={handleCommit}>提交审核</Button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    );
}

export default BiographicalNotesDetails;